/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmc.rra.controller;

import com.cmc.rra.forms.TransactionDetailsForm;
import com.cmc.rra.service.TaxTypeDetailsService;
import com.cmc.rra.service.impl.TaxTypeDetailsServiceImpl;
import com.cmc.rra.sub.TaxTypeDetails;
import com.cmc.rra.sub.impl.TaxTypeDetailsImpl;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;

/**
 *
 * @author cmc
 */
@Controller
@RequestMapping("/saveTaxType")
public class TaxDetailsController {
    
    TaxTypeDetails taxTypeDetails = null;
    TaxTypeDetailsService detailsService = null;
    
    @RequestMapping(method = RequestMethod.POST) 
    public String saveTaxForm(@ModelAttribute TransactionDetailsForm transactionDetailsForm,WebRequest request, HttpServletRequest req, HttpServletResponse res){        
        String code = (String) req.getParameter("codeType");
        String name = (String) req.getParameter("codeName");        
        
        detailsService = new TaxTypeDetailsServiceImpl();
        
        taxTypeDetails = new TaxTypeDetailsImpl();
        taxTypeDetails.setTaxTypeCode(code);
        taxTypeDetails.setTaxTypeName(name);
        
        detailsService.create(taxTypeDetails);
               
        TaxTypeDetails taxTypeDetails1 = detailsService.getByTaxTypeNumber(taxTypeDetails.getTaxTypeNumber());
        request.setAttribute("taxCode", taxTypeDetails1, WebRequest.SCOPE_REQUEST);
        
        return "transactionForm";
    }
    
}
